package com.ruoyi.datam.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.datascope.annotation.DataScope;
import com.ruoyi.datam.service.IWiOrganBService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.domain.base.datam.WiOrganB;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 水管机构登记Controller
 * 
 * @author hwd
 * @date 2023-02-15
 */
@RestController
@RequestMapping("/WiOrganB")
public class WiOrganBController extends BaseController
{
    @Autowired
    private IWiOrganBService wiOrganBService;

    /**
     * 获取机构树形列表
     */
    @DataScope(organAlias = "organb")
    @GetMapping("/treeList")
    public AjaxResult treeList(WiOrganB wiOrganB){
        List<WiOrganB> list = wiOrganBService.treeList(wiOrganB);
        return AjaxResult.success(list);
    }

    /**
     * 查询水管机构登记列表
     */
    @RequiresPermissions("datam:WiOrganB:list")
    @GetMapping("/list")
    public TableDataInfo list(WiOrganB wiOrganB)
    {
        startPage();
        List<WiOrganB> list = wiOrganBService.selectWiOrganBList(wiOrganB);
        return getDataTable(list);
    }

    /**
     * 导出水管机构登记列表
     */
    @RequiresPermissions("datam:WiOrganB:export")
    @Log(title = "水管机构登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WiOrganB wiOrganB)
    {
        List<WiOrganB> list = wiOrganBService.selectWiOrganBList(wiOrganB);
        ExcelUtil<WiOrganB> util = new ExcelUtil<WiOrganB>(WiOrganB.class);
        util.exportExcel(response, list, "水管机构登记数据");
    }

    /**
     * 获取水管机构登记详细信息
     */
    @RequiresPermissions("datam:WiOrganB:query")
    @GetMapping(value = "/{orgCd}")
    public AjaxResult getInfo(@PathVariable("orgCd") String orgCd)
    {
        return success(wiOrganBService.selectWiOrganBByOrgCd(orgCd));
    }

    /**
     * 新增水管机构登记
     */
    @RequiresPermissions("datam:WiOrganB:add")
    @Log(title = "水管机构登记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WiOrganB wiOrganB)
    {
        if (wiOrganB.getParentOrgCd()==null){
            return error("请选择上级水管机构");
        }
        return toAjax(wiOrganBService.insertWiOrganB(wiOrganB));
    }

    /**
     * 修改水管机构登记
     */
    @RequiresPermissions("datam:WiOrganB:edit")
    @Log(title = "水管机构登记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WiOrganB wiOrganB)
    {
        return toAjax(wiOrganBService.updateWiOrganB(wiOrganB));
    }

    /**
     * 删除水管机构登记
     */
    @RequiresPermissions("datam:WiOrganB:remove")
    @Log(title = "水管机构登记", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orgCds}")
    public AjaxResult remove(@PathVariable String[] orgCds)
    {
        return toAjax(wiOrganBService.deleteWiOrganBByOrgCds(orgCds));
    }
}
